package com.jgame.secondarymarket.interfaces.api.product;

import com.jgame.secondarymarket.application.service.product.PropertiesApplicationService;
import com.jgame.secondarymarket.infrastructure.common.model.response.Result;
import com.jgame.secondarymarket.interfaces.assembler.product.ProductPropertiesAssembler;
import com.jgame.secondarymarket.interfaces.dto.product.ProductPropertiesDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @title: PeopertiesApi
 * @Author Wangsj
 * @Date: 2021/7/23
 */
@RestController
@RequestMapping("product")
@Api(tags = {"商品属性"})
public class PropertiesApi {

    @Autowired
    PropertiesApplicationService propertiesApplicationService;

    @ApiOperation(value = "删除商品属性")
    @DeleteMapping("/{productId}/properties")
    public Result del(@PathVariable(value = "productId") Long productId, @RequestBody List<Long> propertiesIds) {
        return Result.op(() -> propertiesApplicationService.delById(productId, propertiesIds));
    }

    @ApiOperation(value = "新增商品属性")
    @PostMapping("/{productId}/properties")
    public Result add(@PathVariable(value = "productId") Long productId, @RequestBody List<ProductPropertiesDTO> properties) {
        return Result.op(() -> propertiesApplicationService.add(productId, ProductPropertiesAssembler.toProductProperties(properties)));
    }
}
